package com.ctshk.sapp.order.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.tour.dto.SeriesOrderDiscountListDTO;
import com.ctshk.rpc.order.tour.req.*;
import com.ctshk.rpc.order.tour.service.ISeriesOrderDiscountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 系列团折扣记录 前端控制器
 * </p>
 *
 * @author 谭响
 * @since 2021-01-22
 */
@Api(value="折扣", tags="折扣")
@RestController
@RequestMapping("/series/order/discount")
public class SeriesOrderDiscountController extends BaseController {

    @DubboReference
    private ISeriesOrderDiscountService iSeriesOrderDiscountService;

    @ApiOperation(value = "添加", notes = "添加（收款管理-折扣-提交審批）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "收款管理-折扣-提交審批", operDesc = "收款管理-折扣-提交審批")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid SeriesOrderDiscountAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderDiscountService.add(req);
    }

    @ApiOperation(value = "列表", notes = "列表（折扣記錄）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "折扣記錄", operDesc = "折扣記錄")
    @PostMapping("/list")
    public Result<PageResponse<SeriesOrderDiscountListDTO>> list(@RequestBody SeriesOrderDiscountListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return Result.success(iSeriesOrderDiscountService.list(req));
    }

    @ApiOperation(value = "删除", notes = "删除（折扣記錄-删除）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "折扣記錄-删除", operDesc = "折扣記錄-删除")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Valid SeriesOrderDiscountDeleteReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderDiscountService.delete(req);
    }

    @ApiOperation(value = "编辑", notes = "编辑（折扣記錄-编辑）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "折扣記錄-编辑", operDesc = "折扣記錄-编辑")
    @PostMapping("/edit")
    public Result edit(@RequestBody @Valid SeriesOrderDiscountEditReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderDiscountService.edit(req);
    }

    @ApiOperation(value = "审核", notes = "审核")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "审核", operDesc = "审核")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid SeriesOrderDiscountApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderDiscountService.approval(req);
    }


}
